package net.asfun.jvalog.task;

import net.asfun.jvalog.domain.Counter;
import net.asfun.jvalog.domain.Dbcache;
import net.asfun.jvalog.domain.Gmcache;
import net.asfun.jvalog.misc.Setting;
import net.asfun.jvalog.service.Painter;
import net.asfun.jvalog.view.SiteInfo;
import static net.asfun.jvalog.misc.Log.logger;

public class DataTask {

	public static void update() {
		boolean isUpdate = false;
		if ( UpdateManager.updCounter ) {
			logger.info("*******************doing counter update");
			Counter.rebuild();
			//TODO if recount takes long time, use task queue to do recounting and then clear cache
			UpdateManager.updm(false);
			isUpdate = true;
		}
		if ( UpdateManager.updStatic ) {
			logger.info("*******************doing static update");
			Setting.reset();
			SiteInfo.reset();
			Painter.reset();
			UpdateManager.upds(false);
			isUpdate = true;
		}
		if ( UpdateManager.updCache ) {
			logger.info("*******************doing cache update");
			Gmcache.clear();
			Dbcache.clear();
			UpdateManager.updc(false);
			isUpdate = true;
		}
		if ( !isUpdate ) {
			logger.info("*******************nothing need update");
		}
	}

}
